﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Gencode.Gengui.Wizzard;
using Gencode.PrsCommon.App;

namespace Gencode.PrsUtil.Dialog.Stammdaten.PersonWizard
{
	public partial class AditionalData : Gencode.Gengui.Wizzard.WizzardControl
	{
		DataView _anstellungen;
		string _mandid;

		public AditionalData(string previousControl, string nextControl, WizzardDialog controler, string mandid)
			: base(previousControl, nextControl, controler)
		{
			this._mandid = mandid;

			InitializeComponent();
			InitializeAnstellungCombo();

			//_initialized = true;

			pensVon.Value = DateTime.Now;
			pensBis.Value = new DateTime(DateTime.Now.AddYears(20).Year, DateTime.Now.Month, DateTime.Now.Day);
		}

		private void InitializeAnstellungCombo()
		{
			_anstellungen = Gencode.PrsCommon.Data.Anstellung.AnstellungData.GetAnstellungenNamen(_mandid);
			comboAnstellung.DataSource = _anstellungen;
			comboAnstellung.DisplayMember = "name";
		}


		public override bool MoveNext()
		{
			Gencode.PrsCommon.Data.Person.SimplePersonData data = Controler.DataObjects.GetType(typeof(Gencode.PrsCommon.Data.Person.SimplePersonData)) as Gencode.PrsCommon.Data.Person.SimplePersonData;

			if (pensVon.Text.CompareTo(string.Empty) == 1)
				data.PensumDatumVon = pensVon.Text;
			else
				return false;

			if (pensBis.Text.CompareTo(string.Empty) == 1)
				data.PensumDatumBis = pensBis.Text;
			else
				return false;

			data.Arbeitspensum = (int)numPens.Value;

			if (comboAnstellung.SelectedIndex >= 0)
			{
				try
				{
					data.AnstellungID = int.Parse(_anstellungen[comboAnstellung.SelectedIndex].Row[0].ToString());
				}
				catch { }
			}
			else
				return false;

			return base.MoveNext();
		}

		private void pensVon_ValueChanged(object sender, EventArgs e)
		{
			//if (_initialized)
				if (pensVon.Value.Day != 1)
				{
					pensVon.Value = new DateTime(pensVon.Value.Year, pensVon.Value.Month, 1);
				}
		}

		private void pensBis_ValueChanged(object sender, EventArgs e)
		{
			//if (_initialized)
				if (pensBis.Value.Day != DateTime.DaysInMonth(pensBis.Value.Year, pensBis.Value.Month))
				{
					pensBis.Value = new DateTime(pensBis.Value.Year, pensBis.Value.Month, DateTime.DaysInMonth(pensBis.Value.Year, pensBis.Value.Month));
				}
		}
	}
}
